#include "user_extern.h"

static uint8_t run(void);
static void win_create(void);
static void update_screen(void);
static void display(void);
static uint8_t button_select(void *arg);
static uint8_t button_enter(void *arg);
static uint8_t button_exit(void *arg);
static uint8_t get_id(void);

static uint8_t subidx = WIN_SUI_SETTING_WIFI;

static Windows window = {
    .id = WIN_UI_OTHERMO,
    .fa_id = WIN_UI_DESKTOP,
    //.son_id = {},
    .name = "othermo",
    .win_status = WINDOWS_STATUS_INIT,
    .run = run,
    .update_screen = update_screen,
    .Dselect = button_select,
    .enter = button_enter,
    .exit = button_exit,
};

static void display(void)
{
    switch (Dsystem.windows_sub_id)
    {
    case WIN_SUI_SETTING_WIFI:
        window.win_status = win5_setting_wifi_display();
        break;
    case WIN_SUI_SETTING_TIME:
        window.win_status = win6_setting_time_display();
        break;
    case WIN_SUI_SETTING_LIGHT:
        window.win_status = win7_setting_light_display();
        break;
    case WIN_SUI_SETTING_TONE:
        window.win_status = win8_setting_tone_display();
        break;
    case WIN_SUI_SETTING_WEATHER:
        window.win_status = win9_setting_weather_display();
        break;
    case WIN_SUI_SETTING_OTA:
        window.win_status = win10_setting_ota_display();
        break;
    case WIN_SUI_SETTING_STATUS:
        window.win_status = win11_setting_status_display();
        break;
    case WIN_SUI_SETTING_TIME_TIME:
        window.win_status = win12_setting_time_time_display();
        break;
    case WIN_SUI_SETTING_TIME_ALARM:
        window.win_status = win12_setting_time_alarm_display();
        break;
    case WIN_SUI_WIZARD_INIT:
        window.win_status = win13_wizard_display();
        break;
    case WIN_SUI_WIZARD_WIFI:
        window.win_status = win14_wizard_wifi_display();
        break;
    case WIN_SUI_WIZARD_LOCAL:
        window.win_status = win15_wizard_local_display();
        break;
    /* DIGIMON */
    case WIN_SDIGI_MENU1_INFO:
        window.win_status = digi01_info_display();
        break;
    case WIN_SDIGI_MENU2_EAT:
        window.win_status = digi02_eat_display();
        break;
    case WIN_SDIGI_MENU3_TRAINING:
        window.win_status = digi03_train_display();
        break;
    case WIN_SDIGI_MENU4_AIBAT:
        window.win_status = digi04_battle_display();
        break;
    case WIN_SDIGI_MENU5_CLEAN:
        window.win_status = digi05_clean_display();
        break;
    case WIN_SDIGI_MENU6_LIGHT:
        window.win_status = digi06_sleep_display();
        break;
    case WIN_SDIGI_MENU7_HEALTH:
        window.win_status = digi07_health_display();
        break;
    case WIN_SDIGI_MENU8_DATABASE:
        window.win_status = digi08_database_display();
        break;
    }
}

static uint8_t button_select(void *arg)
{
    switch (Dsystem.windows_sub_id)
    {
    case WIN_SUI_SETTING_WIFI:
        win5_setting_wifi_btn_select(arg);
        break;
    case WIN_SUI_SETTING_TIME:
        win6_setting_time_btn_select(arg);
        break;
    case WIN_SUI_SETTING_LIGHT:
        win7_setting_light_btn_select(arg);
        break;
    case WIN_SUI_SETTING_TONE:
        win8_setting_tone_btn_select(arg);
        break;
    case WIN_SUI_SETTING_WEATHER:
        win9_setting_weather_btn_select(arg);
        break;
    case WIN_SUI_SETTING_OTA:
        break;
    case WIN_SUI_SETTING_STATUS:
        win11_setting_status_btn_select(arg);
        break;
    case WIN_SUI_SETTING_TIME_TIME:
        win12_setting_time_time_btn_select(arg);
        break;
    case WIN_SUI_SETTING_TIME_ALARM:
        win12_setting_time_alarm_btn_select(arg);
        break;
    case WIN_SUI_WIZARD_INIT:
        win13_wizard_btn_select(arg);
        break;
    case WIN_SUI_WIZARD_WIFI:
        break;
    case WIN_SUI_WIZARD_LOCAL:
        win15_wizard_btn_select(arg);
        break;

    /* DIGIMON */
    case WIN_SDIGI_MENU1_INFO:
        digi01_info_btn_select(arg);
        break;
    case WIN_SDIGI_MENU2_EAT:
        digi02_eat_btn_select(arg);
        break;
    case WIN_SDIGI_MENU3_TRAINING:
        digi03_train_btn_select(arg);
        break;
    case WIN_SDIGI_MENU4_AIBAT:
        digi04_battle_btn_select(arg);
        break;
    case WIN_SDIGI_MENU5_CLEAN:
        break;
    case WIN_SDIGI_MENU6_LIGHT:
        digi06_sleep_btn_select(arg);
        break;
    case WIN_SDIGI_MENU7_HEALTH:
        digi07_health_btn_select(arg);
        break;
    case WIN_SDIGI_MENU8_DATABASE:
        digi08_database_btn_select(arg);
        break;
    }
    return 0;
}

static uint8_t button_enter(void *arg)
{
    switch (Dsystem.windows_sub_id)
    {
    case WIN_SUI_SETTING_WIFI:
        window.win_status = win5_setting_wifi_btn_enter(arg);
        break;
    case WIN_SUI_SETTING_TIME:
        window.win_status = win6_setting_time_btn_enter(arg);
        break;
    case WIN_SUI_SETTING_LIGHT:
        window.win_status = win7_setting_light_btn_enter(arg);
        break;
    case WIN_SUI_SETTING_TONE:
        window.win_status = win8_setting_tone_btn_enter(arg);
        break;
    case WIN_SUI_SETTING_WEATHER:
        window.win_status = win9_setting_weather_btn_enter(arg);
        break;
    case WIN_SUI_SETTING_OTA:
        window.win_status = win10_setting_ota_btn_enter(arg);
        break;
    case WIN_SUI_SETTING_STATUS:
        window.win_status = win11_setting_status_btn_enter(arg);
        break;
    case WIN_SUI_SETTING_TIME_TIME:
        window.win_status = win12_setting_time_time_btn_enter(arg);
        break;
    case WIN_SUI_SETTING_TIME_ALARM:
        window.win_status = win12_setting_time_alarm_btn_enter(arg);
        break;
    case WIN_SUI_WIZARD_INIT:
        window.win_status = win13_wizard_btn_enter(arg);
        break;
    case WIN_SUI_WIZARD_WIFI:
        break;
    case WIN_SUI_WIZARD_LOCAL:
        window.win_status = win15_wizard_btn_enter(arg);
        break;
    /* DIGIMON */
    case WIN_SDIGI_MENU1_INFO:
        window.win_status = digi01_info_btn_enter(arg);
        break;
    case WIN_SDIGI_MENU2_EAT:
        window.win_status = digi02_eat_btn_enter(arg);
        break;
    case WIN_SDIGI_MENU3_TRAINING:
        window.win_status = digi03_train_btn_enter(arg);
        break;
    case WIN_SDIGI_MENU4_AIBAT:
        window.win_status = digi04_battle_btn_enter(arg);
        break;
    case WIN_SDIGI_MENU5_CLEAN:
        break;
    case WIN_SDIGI_MENU6_LIGHT:
        window.win_status = digi06_sleep_btn_enter(arg);
        break;
    case WIN_SDIGI_MENU7_HEALTH:
        window.win_status = digi07_health_btn_enter(arg);
        break;
    case WIN_SDIGI_MENU8_DATABASE:
        window.win_status = digi08_database_btn_enter(arg);
        break;
    }
    return 0;
}

static uint8_t button_exit(void *arg)
{
    switch (Dsystem.windows_sub_id)
    {
    case WIN_SUI_SETTING_WIFI:
        window.win_status = win5_setting_wifi_btn_exit(arg);
        break;
    case WIN_SUI_SETTING_TIME:
        window.win_status = win6_setting_time_btn_exit(arg);
        break;
    case WIN_SUI_SETTING_LIGHT:
        window.win_status = win7_setting_light_btn_exit(arg);
        break;
    case WIN_SUI_SETTING_TONE:
        window.win_status = win8_setting_tone_btn_exit(arg);
        break;
    case WIN_SUI_SETTING_WEATHER:
        window.win_status = win9_setting_weather_btn_exit(arg);
        break;
    case WIN_SUI_SETTING_OTA:
        window.win_status = win10_setting_ota_btn_exit(arg);
        break;
    case WIN_SUI_SETTING_STATUS:
        window.win_status = win11_setting_status_btn_exit(arg);
        break;
    case WIN_SUI_SETTING_TIME_TIME:
        window.win_status = win12_setting_time_time_btn_exit(arg);
        break;
    case WIN_SUI_SETTING_TIME_ALARM:
        window.win_status = win12_setting_time_alarm_btn_exit(arg);
        break;
    case WIN_SUI_WIZARD_INIT:
        window.win_status = win13_wizard_btn_exit(arg);
        break;
    case WIN_SUI_WIZARD_WIFI:
        break;
    case WIN_SUI_WIZARD_LOCAL:
        window.win_status = win15_wizard_btn_exit(arg);
        break;

    /* DIGIMON */
    case WIN_SDIGI_MENU1_INFO:
        window.win_status = digi01_info_btn_exit(arg);
        break;
    case WIN_SDIGI_MENU2_EAT:
        window.win_status = digi02_eat_btn_exit(arg);
        break;
    case WIN_SDIGI_MENU3_TRAINING:
        window.win_status = digi03_train_btn_exit(arg);
        break;
    case WIN_SDIGI_MENU4_AIBAT:
        window.win_status = digi04_battle_btn_exit(arg);
        break;
    case WIN_SDIGI_MENU5_CLEAN:
        break;
    case WIN_SDIGI_MENU6_LIGHT:
        window.win_status = digi06_sleep_btn_exit(arg);
        break;
    case WIN_SDIGI_MENU7_HEALTH:
        window.win_status = digi07_health_btn_exit(arg);
        break;
    case WIN_SDIGI_MENU8_DATABASE:
        window.win_status = digi08_database_btn_exit(arg);
        break;
    }
    return 0;
}

/* **************************************************************************************** */

static void win_create(void)
{
    switch (Dsystem.windows_sub_id)
    {
    case WIN_SUI_WIZARD_WIFI:
        win14_wizard_create();
        break;
    }
}

static void update_screen(void)
{
    oled.refresh_all(1);
}

static uint8_t run(void)
{
    switch (window.win_status)
    {
    case WINDOWS_STATUS_NONE:
        return 0;
        break;
    case WINDOWS_STATUS_INIT:
        win_create();
        display();
        window.win_status = WINDOWS_STATUS_DIS_ONLY;
        break;
    case WINDOWS_STATUS_DIS_ONLY:
        display();
        break;
    }
    return window.win_status;
}

static uint8_t get_id(void)
{
    return window.id;
}

void win04_othermo_init(void)
{
    windows[get_id()] = window;
}
